﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "GbmpTypeDefs.h"
#include "NdbPropertySchemaType.h"
#include "ElementId.h"
#include <vector>
#include <map>

namespace gcmp
{
    class IIOStream;
    class NdbObject;
    struct NdbArchiveResult;
    class IElementManager;

    typedef std::vector<char> NdbElementRawData;

    typedef std::vector<char> NdbElementAttributeRawData;

    class GCMP_DATABASE_EXPORT IDbObjectArchive
    {
        DEFINE_CAST_BASE(gcmp::IDbObjectArchive)
    public:
        virtual ~IDbObjectArchive() = 0;

        virtual IIOStream & GetIOStream() = 0;

        virtual Int64 GetObjectId() const = 0;

        virtual UInt64 WriteObject(
            const NdbObject *pNdbObject,
            NdbPropertyUtils::BehavioursAdapter adapter
        ) = 0;

        virtual IDbObjectArchive & WriteNdbElementRawData(
            Int64 elementId,
            const NdbElementRawData & elementRawData,
            const std::map<std::wstring, NdbElementAttributeRawData>& attributesRawDataOfElement,
            NdbArchiveResult & res
        ) = 0;

        virtual IDbObjectArchive & ReadNdbElementsRawData(
            UInt32 schemaMajorVersion,
            UInt64 elementCount,
            bool byElementIndex,
            UInt64 version,
            std::vector<Int64> & elementIds,
            std::vector<Int64> & offsets,
            std::vector<UInt64> & lengths,
            std::vector<NdbElementRawData> & elementsRawData,
            std::vector<std::map<std::wstring, NdbElementAttributeRawData> > & attributesRawDataOfElements, 
            NdbArchiveResult & res,
            bool & allElementsRead
        ) = 0;

        virtual IDbObjectArchive & ReadNdbElementAttribute(
            std::wstring & fileName, 
            std::vector<std::map<std::wstring, NdbElementAttributeRawData> >& attributesRawDataOfElements
        ) = 0;
   
    };

    inline IDbObjectArchive::~IDbObjectArchive() {}
}
